/**
 * 爬虫相关类型定义
 */

export interface CrawlerConfig {
  maxContentChapters: number;
  batchSize: number;
  delayBetweenRequests: number;
  maxRetries: number;
  userAgent: string;
  timeout: number;
}

export interface ChapterCrawlResult {
  chapter: ParsedChapterData;
  success: boolean;
  error?: string;
  duration: number;
}

export interface NovelCrawlResult {
  novel: ParsedNovelData;
  chapters: ParsedChapterData[];
  success: boolean;
  error?: string;
  duration: number;
  stats: {
    totalChapters: number;
    successfulChapters: number;
    failedChapters: number;
    freeChapters: number;
    paidChapters: number;
  };
}

export interface ParsedNovelData {
  title: string;
  author: string;
  updateTime: string;
  status: string;
  category: string;
  wordCount: number;
  description: string;
  tags: string;
  cover?: string;
}

export interface ParsedChapterData {
  title: string;
  isFree: number;
  url: string;
  content: string;
  index: number;
  volumeName?: string;
  wordCount?: number;
  crawlTime?: Date;
}

export interface CrawlStats {
  startTime: Date;
  endTime?: Date;
  duration?: number;
  totalChapters: number;
  successfulChapters: number;
  failedChapters: number;
  skippedChapters: number;
  averageChapterLength: number;
  errors: Array<{
    chapterIndex: number;
    chapterTitle: string;
    error: string;
    timestamp: Date;
  }>;
}

export type CrawlerStatus =
  | 'idle'
  | 'running'
  | 'completed'
  | 'failed'
  | 'paused';

export interface CrawlerProgress {
  status: CrawlerStatus;
  currentChapter: number;
  totalChapters: number;
  progress: number; // 0-100
  estimatedTimeRemaining?: number; // seconds
  currentOperation: string;
}

export interface AntiCrawlerDetection {
  hasCaptcha: boolean;
  hasRateLimit: boolean;
  hasAccessDenied: boolean;
  suspiciousElements: string[];
  recommendations: string[];
}
